package books4africa



import grails.test.mixin.*
import org.junit.*

/**
 * See the API for {@link grails.test.mixin.domain.DomainClassUnitTestMixin} for usage instructions
 */
@TestFor(Teacher)
class TeacherTests {

    void testGradeLevel() {
		//test upper and lower bounds on grade level
		Teacher testLower = new Teacher(username: "test@test.com", password: "password",
			firstName:"Test", lastName: "Subject", 
			schoolName: "Test School", streetAddress: "12 Test Blvd", town:"Testshire",
			region: "Cape Test", country: "Testaria", phoneNum: "555-555-5555", 
			gradeLevel: -1);
		
		Teacher testUpper = new Teacher(username: "test@test.com", password: "password",
			firstName:"Test", lastName: "Subject", 
			schoolName: "Test School", streetAddress: "12 Test Blvd", town:"Testshire",
			region: "Cape Test", country: "Testaria", phoneNum: "555-555-5555", 
			gradeLevel: 7);
		
		Teacher testMiddle = new Teacher(username: "test@test.com", password: "password",
			firstName:"Test", lastName: "Subject", 
			schoolName: "Test School", streetAddress: "12 Test Blvd", town:"Testshire",
			region: "Cape Test", country: "Testaria", phoneNum: "555-555-5555", 
			gradeLevel: 3);
		
		assertFalse(testLower.validate());
		assertFalse(testUpper.validate());
		assertTrue(testMiddle.validate());
    }
	
	void testUsername(){
		//test length limits on username
		Teacher tooShort = new Teacher(username: "a@b.c", password: "password",
			firstName:"Test", lastName: "Subject", 
			schoolName: "Test School", streetAddress: "12 Test Blvd", town:"Testshire",
			region: "Cape Test", country: "Testaria", phoneNum: "555-555-5555", 
			gradeLevel: 3);
		
		Teacher tooLong = new Teacher(username: "123456789012345678901234567890123456789011@test.com", password: "password",
			firstName:"Test", lastName: "Subject", 
			schoolName: "Test School", streetAddress: "12 Test Blvd", town:"Testshire",
			region: "Cape Test", country: "Testaria", phoneNum: "555-555-5555", 
			gradeLevel: 3);
		
		Teacher justRight = new Teacher(username: "test@test.com", password: "password",
			firstName:"Test", lastName: "Subject", 
			schoolName: "Test School", streetAddress: "12 Test Blvd", town:"Testshire",
			region: "Cape Test", country: "Testaria", phoneNum: "555-555-5555", 
			gradeLevel: 3); 
		
		assertFalse(tooShort.validate());
		assertFalse(tooLong.validate());
		assertTrue(justRight.validate());
	}
	
	void testPassword(){
		//test length limits on password
		Teacher tooShort = new Teacher(username: "test@test.com", password: "passw",
			firstName:"Test", lastName: "Subject",
			schoolName: "Test School", streetAddress: "12 Test Blvd", town:"Testshire",
			region: "Cape Test", country: "Testaria", phoneNum: "555-555-5555",
			gradeLevel: 3);
		
		Teacher tooLong = new Teacher(username: "test@test.com", password: "password1",
			firstName:"Test", lastName: "Subject",
			schoolName: "Test School", streetAddress: "12 Test Blvd", town:"Testshire",
			region: "Cape Test", country: "Testaria", phoneNum: "555-555-5555",
			gradeLevel: 3);
		
		Teacher justRight = new Teacher(username: "test@test.com", password: "passwor",
			firstName:"Test", lastName: "Subject",
			schoolName: "Test School", streetAddress: "12 Test Blvd", town:"Testshire",
			region: "Cape Test", country: "Testaria", phoneNum: "555-555-5555",
			gradeLevel: 3);
		
		assertFalse(tooShort.validate());
		assertFalse(tooLong.validate());
		assertTrue(justRight.validate());
	}
}
